package com.lbj.googleplay.googleplay100.ui.holder;

import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.lbj.googleplay.googleplay100.R;
import com.lbj.googleplay.googleplay100.domain.AppInfo;
import com.lbj.googleplay.googleplay100.http.HttpHelper;
import com.lbj.googleplay.googleplay100.utils.UIUtils;

import org.xutils.ImageManager;
import org.xutils.image.ImageOptions;
import org.xutils.x;

public class AppHolder extends BaseHolder<AppInfo> {

    private TextView tv_name;
    private TextView tv_size;
    private ImageView iv_icon;
    private TextView tv_des;
    private RatingBar rb_star;
    private ImageManager imageManager;

    @Override
    public View initView() {
        //1.加载布局
        View view = UIUtils.inflate(R.layout.list_item_home);
        //2.初始化控件
         tv_name = view.findViewById(R.id.tv_name);
         tv_size = view.findViewById(R.id.tv_size);
         iv_icon = view.findViewById(R.id.iv_icon);
         tv_des = view.findViewById(R.id.tv_des);
         rb_star = view.findViewById(R.id.rb_star);
         imageManager = x.image();
         return view;
    }

    @Override
    public void refreshView(AppInfo data) {
        tv_name.setText(data.name);
        tv_des.setText(data.des);
        tv_size.setText(android.text.format.Formatter.formatFileSize(UIUtils.getContext(),data.size));
        ImageOptions.Builder builder = new ImageOptions.Builder();
        ImageOptions options = builder.build();
        imageManager.bind(iv_icon, HttpHelper.URL+"image?name="+data.iconUrl,options);
        rb_star.setRating(data.stars);
    }

}
